package gui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;

/**
 * @file CustPurchase.java
 * @version 0.1
 * @author James Dibble 10009689
 */
@Entity
@Table(name = "cust_purchase", catalog = "dms", schema = "")
@NamedQueries({
    @NamedQuery(name = "CustPurchase.findAll", query = "SELECT c FROM CustPurchase c"),
    @NamedQuery(name = "CustPurchase.findById", query = "SELECT c FROM CustPurchase c WHERE c.id = :id"),
    @NamedQuery(name = "CustPurchase.findByCustomer", query = "SELECT c FROM CustPurchase c WHERE c.customer = :customer"),
    @NamedQuery(name = "CustPurchase.findByCarPurchase", query = "SELECT c FROM CustPurchase c WHERE c.carPurchase = :carPurchase"),
    @NamedQuery(name = "CustPurchase.findByDatePurchased", query = "SELECT c FROM CustPurchase c WHERE c.datePurchased = :datePurchased"),
    @NamedQuery(name = "CustPurchase.findByPurchasePrice", query = "SELECT c FROM CustPurchase c WHERE c.purchasePrice = :purchasePrice")})
public class CustPurchase implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "customer")
    private int customer;
    @Basic(optional = false)
    @Column(name = "car_purchase")
    private int carPurchase;
    @Basic(optional = false)
    @Column(name = "date_purchased")
    @Temporal(TemporalType.DATE)
    private Date datePurchased;
    @Basic(optional = false)
    @Column(name = "purchase_price")
    private long purchasePrice;
    // <editor-fold defaultstate="collapsed" desc="Attributes">
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public CustPurchase() {
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Methods">
    // </editor-fold>

    public CustPurchase(Integer id) {
        this.id = id;
    }

    public CustPurchase(Integer id, int customer, int carPurchase, Date datePurchased, long purchasePrice) {
        this.id = id;
        this.customer = customer;
        this.carPurchase = carPurchase;
        this.datePurchased = datePurchased;
        this.purchasePrice = purchasePrice;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public int getCustomer() {
        return customer;
    }

    public void setCustomer(int customer) {
        int oldCustomer = this.customer;
        this.customer = customer;
        changeSupport.firePropertyChange("customer", oldCustomer, customer);
    }

    public int getCarPurchase() {
        return carPurchase;
    }

    public void setCarPurchase(int carPurchase) {
        int oldCarPurchase = this.carPurchase;
        this.carPurchase = carPurchase;
        changeSupport.firePropertyChange("carPurchase", oldCarPurchase, carPurchase);
    }

    public Date getDatePurchased() {
        return datePurchased;
    }

    public void setDatePurchased(Date datePurchased) {
        Date oldDatePurchased = this.datePurchased;
        this.datePurchased = datePurchased;
        changeSupport.firePropertyChange("datePurchased", oldDatePurchased, datePurchased);
    }

    public long getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(long purchasePrice) {
        long oldPurchasePrice = this.purchasePrice;
        this.purchasePrice = purchasePrice;
        changeSupport.firePropertyChange("purchasePrice", oldPurchasePrice, purchasePrice);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CustPurchase)) {
            return false;
        }
        CustPurchase other = (CustPurchase) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "gui.CustPurchase[ id=" + id + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
